package com.novel.service.impl;

import com.novel.mapper.AuthorMapper;
import com.novel.service.AuthorService;
import com.reading.pojo.Author;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AuthorServiceImpl implements AuthorService {

    @Autowired
    private AuthorMapper authorMapper;

    @Override
    public List<Map<String, String>> findHotAuthor() {
        //新建list集合
        ArrayList<Map<String,String>> list = new ArrayList<>();
        List<Author> authorList = authorMapper.findAll();

        //循环
        for (int i = 0; i < authorList.size(); i++) {
            HashMap<String, String> map = new HashMap<>();
            map.put("id",authorList.get(i).getId().toString());
            map.put("name",authorList.get(i).getAuthornickname());
            map.put("avatar",authorList.get(i).getPhoto());
            list.add(map);
        }
        return list;
    }

    @Override
    public List<Author> findAll() {
        return authorMapper.findAll();
    }
}
